package com.mz.mattress.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mz.mattress.api.entity.MemberCoupon;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MemberCouponMapper extends BaseMapper<MemberCoupon> {

//    @Select("select id,name,discount,full_money,minus_money from mz_member_coupon where member_id=#{memberId} and full_money<=#{money} and status=0 and deleted=0 order by minus_money desc")

    List<MemberCoupon> list(@Param("memberId") Long memberId, @Param("money") Integer money, @Param("goodsId") Integer goodsId);

    @Select("select id,name,discount,full_money,minus_money from mz_member_coupon where member_id=#{memberId} and status=0 and deleted=0")
    List<MemberCoupon> listAll(@Param("memberId") Long memberId);

    @Update("update mz_member_coupon set deleted=1 where order_id=#{orderId}")
    void cleanMemberCouponByOrderId(@Param("orderId") Long orderId);

    @Update("update mz_member_coupon set status=0,used_time=null,order_id=null where id=#{id}")
    void backMemberCoupon(@Param("id") Integer id);

}
